/*
 * @Author: baoshijie baoshijie
 * @Date: 2023-01-31 15:05:48
 * @LastEditors: baoshijie baoshijie
 * @LastEditTime: 2023-01-31 15:30:14
 * @FilePath: \notam\src\directive\permission\hasBtn.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * v-hasBtn 按钮权限处理
    */

import store from '@/store';

export default {
    mounted(el, binding, vnode) {
        const { value } = binding;
        const roles = store.getters && store.getters.btnPermissionData;
        if (value) {
            //如果传入的元素value不在权限数组里，则不可显示
            const hasRole = roles.indexOf(value);
            if (hasRole==-1) {
                el.parentNode && el.parentNode.removeChild(el);
            }
        } else {
            throw new Error(`请设置按钮权限"`);
        }
    },
};
